package com.jiamao.goplay.adapter;

import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.LayoutRes;
import androidx.annotation.RequiresApi;
import androidx.databinding.ViewDataBinding;

import com.bumptech.glide.Glide;
import com.itheima.roundedimageview.RoundedImageView;
import com.jiamao.goplay.R;
import com.jiamao.goplay.ui.discover.vm.CityMenuItemVM;
import com.jiamao.goplay.ui.user.vm.UserWantGotoItemVM;
import com.jiamao.goplay.view.DiscussionAvatarViews;
import com.jiamao.goplay.view.PileLayout;

import java.util.ArrayList;

import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;

public class UserWanToGoAdapter extends BindingRecyclerViewAdapter {

    Context context;
    LayoutInflater inflater;
    boolean isEdit;
    public UserWanToGoAdapter(Context context){
        this.context = context;
         inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewDataBinding onCreateBinding(LayoutInflater inflater, @LayoutRes int layoutId, ViewGroup viewGroup) {
        ViewDataBinding binding = super.onCreateBinding(inflater, layoutId, viewGroup);
        return binding;
    }

    private int iondex = 0 ;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindBinding(ViewDataBinding binding, int bindingVariable, @LayoutRes int layoutId, int position, Object item) {
        super.onBindBinding(binding, bindingVariable, layoutId, position, item);
                if (item instanceof UserWantGotoItemVM){
                    ImageView btndel = binding.getRoot().findViewById(R.id.btn_del_addr);
                    if (btndel!=null){
                        if (isEdit){
                            btndel.setVisibility(View.VISIBLE);
                        }else {
                            btndel.setVisibility(View.GONE);
                        }
                    }
                    DiscussionAvatarViews discussionAvatarView = binding.getRoot().findViewById(R.id.pile_layout);
                    discussionAvatarView.initDatas( ((UserWantGotoItemVM) item).list.get());

//                    PileLayout discussionAvatarView = binding.getRoot().findViewById(R.id.pile_layout);
//                    discussionAvatarView.removeAllViews();
//
//                    if (((UserWantGotoItemVM) item).list.get() == null){
//                        return;
//                    }
//                    for (int i = 0; i < ((UserWantGotoItemVM) item).list.get().size(); i++) {
//
//                        RoundedImageView imageView = (RoundedImageView) inflater.inflate(R.layout.user_array_img,discussionAvatarView,false);
//                        Glide.with(context).load(((UserWantGotoItemVM) item).list.get().get(i)).into(imageView);
//                        discussionAvatarView.addView(imageView);
//                    }

             }
    }

    public void refreshUI(){

        CityMenuItemVM vm = (CityMenuItemVM) getAdapterItem(iondex);
        vm.select.set(false);
//        notifyItemChanged(iondex);
        notifyDataSetChanged();

    }

    public void updateEdit(boolean flag){

        isEdit = flag;
//        notifyItemChanged(iondex);
        notifyDataSetChanged();

    }


//    @Override
//    public void onBindBinding(@NonNull ViewDataBinding binding, int variableId, int layoutRes, int position, Object item) {
//        super.onBindBinding(binding, variableId, layoutRes, position, item);
//
//        if (item instanceof CityMenuItemVM){
//            CityMenuItemVM vm  = (CityMenuItemVM) item;
//
//        }
//
//    }
}
